package com.shengzai.hbase;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.exceptions.DeserializationException;
import org.apache.hadoop.hbase.util.Bytes;

import java.io.IOException;

public class CreateTable {
    public static void main(String[] args) throws IOException, DeserializationException {
        Configuration conf = new Configuration();
        conf.set("hbase.zookeeper.quorum","master,node1,node2");
        Connection connection = ConnectionFactory.createConnection(conf);

        Admin admin = connection.getAdmin();
        TableName apiStudent = TableName.valueOf("api_test:dianxin");
        HTableDescriptor hTableDescriptor = new HTableDescriptor(apiStudent);
        HTableDescriptor studentsInfo = hTableDescriptor.addFamily(new HColumnDescriptor("dianXinInfo"));
        HTableDescriptor studentsScore = hTableDescriptor.addFamily(new HColumnDescriptor(new HColumnDescriptor("students_score2")));
        admin.createTable(hTableDescriptor);
        admin.close();
        connection.close();
    }
}       //  put 'api_test:api_student','1810404125','students_info:name','sz'
